<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use app\common\ApiStatus;
use Webman\Route;
use app\middleware\ApiAuthCheck;

//use app\middleware\Ajax;
//use app\middleware\CheckIndex;

//************************ ↓↓ WEB 接口 ↓↓ ************************
//Route::get('/', [app\web\controller\Index::class, 'index'])->middleware([CheckIndex::class]);
//Route::get('/outside/captcha/', [app\web\controller\Outside::class, 'captcha']);
//Route::get('/help/agreement/{id:\d+}/', [app\web\controller\Agreement::class, 'index']);
//
//Route::group('/converter', function () {
//    Route::get('/{title}', function ($request, $title) {
//        return redirect("/converter/{$title}/");
//    });
//    Route::get('/{title}/', [app\web\controller\Converter::class, 'index']);
//});

//Route::group('/pay', function () {
//    Route::get('/wechatpay/{order_no}/', [app\web\controller\Pay::class, 'wechatpay'])->middleware([ApiAuthCheck::class]);
//    Route::get('/alipay/{order_no}/', [app\web\controller\Pay::class, 'alipay'])->middleware([ApiAuthCheck::class]);
//    Route::get('/qrcode/{order_no}/', [app\web\controller\Pay::class, 'qrcode']);
//    Route::post('/wechat/notify/', [app\web\controller\Pay::class, 'wechat_notify']);   // 微信支付异步回调 POST
//    Route::post('/alipay/notify/', [app\web\controller\Pay::class, 'alipay_notify']);   // 支付宝支付异步回调 POST
//});
//
//Route::group('/login', function () {
//    Route::any('/wechat/', [app\web\controller\Login::class, 'wechat']);              // 微信扫码登录
//    Route::any('/wx/', [app\web\controller\Login::class, 'wx']);                      // QQ登录
//    Route::any('/qq/', [app\web\controller\Login::class, 'qq']);                      // QQ登录
//    Route::get('/out', [app\web\controller\Login::class, 'out']);
//    Route::get('/qqcallback', [app\web\controller\Login::class, 'qqcallback']);
//});
//
//Route::group('/user', function () {
//    Route::get('', function () {
//        return redirect('/user/');
//    });
//    Route::get('/{title}', function ($request, $title) {
//        return redirect("/user/{$title}/");
//    });
//    Route::get('/index/', function () {
//        return redirect("/user/");
//    });
//    Route::get('/', [app\web\controller\User::class, 'index'])->middleware([ApiAuthCheck::class]);
//});
//
//Route::group('/ajax', function () {
//    Route::get('', function () {
//        return redirect('/ajax/');
//    });
//    Route::get('/{title}', function ($request, $title) {
//        return redirect("/ajax/{$title}/");
//    });
//    Route::any('/upload/', [app\web\controller\Ajax::class, 'upload']);
//    Route::any('/converter/', [app\web\controller\Ajax::class, 'converter']);
//    Route::any('/downloadObject/', [app\web\controller\Ajax::class, 'downloadObject']);
//    Route::any('/deleteObject/', [app\web\controller\Ajax::class, 'deleteObject']);
//    Route::any('/payFor/', [app\web\controller\Ajax::class, 'payFor']);
//    Route::any('/pay_active/', [app\web\controller\Ajax::class, 'pay_active']);
//})->middleware([Ajax::class, ApiAuthCheck::class]);
//
//Route::group('/ajax', function () {
//    Route::any('/phoneLogin/', [app\web\controller\Ajax::class, 'phoneLogin']);
//    Route::any('/send_sms/', [app\web\controller\Ajax::class, 'send_sms']);
//    Route::any('/wechat_login/', [app\web\controller\Ajax::class, 'wechatLogin']);
//})->middleware([Ajax::class]);

//Route::get('/web/api/agreement/{id:\d+}', [app\web\controller\Agreement::class, 'api']);

//************************ ↑↑ WEB 接口 ↑↑ ************************

//************************ ↓↓ API 接口 ↓↓ ************************
// API接口已启用自动路由功能，如果需要特别配置，可以单独控制
Route::group('/api', function () {
    Route::any('/aes_test', function ($request) {
        $key  = \app\service\AesService::instance()->setkey('T3lUf3t3pdHzSx8U')->encrypt('/v1/auth/ossStsToken' . time());
        $data = [
            'key' => urldecode($key),
        ];
        return json($data);
    });
});
Route::group('/h5', function () {
    Route::get('/agreement/{id:\d+}', [app\h5\v1\controller\Web::class, 'agreement']);
    Route::get('/audioShar/{id:\d+}', [app\h5\v1\controller\Web::class, 'audioShar']);
    Route::get('/payCallback/alipay', [app\h5\v1\controller\PayCallback::class, 'alipay']);
    Route::get('/audio/get', [app\h5\v1\controller\Audio::class, 'get']);
    Route::get('/audio/checkqsenckey', [app\h5\v1\controller\Audio::class, 'checkqsenckey']);
    Route::any('/payCallback/wechat/', [app\h5\v1\controller\PayCallback::class, 'wechat']);
    Route::any('/payCallback/wechatRechargeDiscountPay/', [app\h5\v1\controller\PayCallback::class, 'wechatRechargeDiscountPay']);
    Route::any('/payCallback/wechatVipcartPay/', [app\h5\v1\controller\PayCallback::class, 'wechatVipcartPay']);
    Route::any('/payCallback/wechatProductPay/', [app\h5\v1\controller\PayCallback::class, 'wechatProductPay']);
    Route::any('/payCallback/apple', [app\h5\v1\controller\PayCallback::class, 'apple']);
});
//************************ ↑↑ API 接口 ↑↑ ************************

Route::fallback(function ($callback) {
    return json(['code' => ApiStatus::API_NOT_FOUND->value, 'msg' => ApiStatus::from(ApiStatus::API_NOT_FOUND->value)->getStatus(), 'request_id' => md5(uniqid(mt_rand(), true))]);
});


Route::get('/robots.txt', function () {
    $content = "User-agent: *";
//    if (ENVIRONMENT == 'DEV') $content .= PHP_EOL . "Disallow: /";
    $headers = ['Content-Type' => 'text/plain'];
    return response($content, 200, $headers);
});
